const BASE_URL = 'https://ilexue.top/'
import store from '../store'
export const myRequest = (url, data, method) => {
	store.commit('switch', {
		code: true
	})
	var token = uni.getStorageSync("token") || "";

	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: method || 'GET',
			data: data || {},
			header: {
				"XX-Device-Type": "wxapp",
				'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
				"XX-User-Type":'user',
				"XX-Token": token,
			},
			success: (res) => {
				store.commit('switch', {
					code: false
				})
				if (res.data.code == '501') {
					uni.removeStorageSync('userInfo');
					uni.removeStorageSync('token'); 
					setTimeout(() => { 
						uni.showToast({ 
							title: '未登录，或登录失效',
							icon: "none"
						})
					}, 1000) 
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}
				if(res.data.code=='401'){
					
				}
				
				resolve(res.data)
			},
			fail: (err) => {
console.log('测试',err)
				uni.showToast({
					title: '请求接口失败',
					icon: "none"
				})
				reject(err.data)
			}
		})
	}).catch((e) => {})
}
export const baseURL = "https://ilexue.top/"
